﻿Public Class Frm_TruongBoPhan


    Private Sub GroupBox9_Enter(sender As Object, e As EventArgs)

    End Sub

    Private Sub Frm_TruongBoPhan_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lbUserName.Text = Frm_Login.username + " (" + Frm_Login.acctype + ")"
        gvPhongChieu_Load()
        cmbTinhTrang.Text = "Hoạt động"
        cmbDKKT.Text = "2D"
        ComboBox_Load()
        gvPhim_Load()
        cmbXemTheoPhim.Text = "Tất cả"
    End Sub
    Private Sub ComboBox_Load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        cmbMaRap.DataSource = bus.GetTable("select * from RAP")
        cmbMaRap.DisplayMember = "MaRap"
        cmbMaRap.ValueMember = "MaRap"
        cmbXemTheoRap.DataSource = bus.GetTable("select * from RAP")
        cmbXemTheoRap.DisplayMember = "MaRap"
        cmbXemTheoRap.ValueMember = "MaRap"
    End Sub
    Public Sub gvPhongChieu_Load()
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        gvPhongChieu.DataSource = bus.GetTable("select * from PHONGCHIEU")
    End Sub


    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If (txtMoTa.Text = "" Or txtSoDay.Text = "" Or txtSoHang.Text = "" Or cmbDKKT.Text = "" Or cmbMaRap.SelectedValue.ToString() = "" Or cmbTinhTrang.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim pc As PhongChieuDTO = New PhongChieuDTO()
            Dim bus As PhongChieuBUS = New PhongChieuBUS()
            pc.SoDayGhe = Convert.ToInt32(txtSoDay.Text)
            pc.SoHangGhe = Convert.ToInt32(txtSoHang.Text)
            pc.MaRap = Convert.ToInt32(cmbMaRap.SelectedValue.ToString())
            pc.MoTa = txtMoTa.Text
            pc.DKKT = cmbDKKT.SelectedItem.ToString()
            pc.TinhTrang = cmbTinhTrang.SelectedItem.ToString()
            bus.Insert(pc)
            gvPhongChieu_Load()
        End If
    End Sub

    Private Sub gvPhongChieu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvPhongChieu.SelectionChanged
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        Try
            If gvPhongChieu.SelectedRows.Count = 0 Then
                Return
            End If
            lbMaPC.Text = gvPhongChieu.CurrentRow.Cells(0).Value.ToString()
            cmbMaRap.Text = bus.GetValue("select MaRap from RAP where MaRap=" + gvPhongChieu.CurrentRow.Cells(1).Value.ToString())
            txtSoDay.Text = gvPhongChieu.CurrentRow.Cells(2).Value.ToString()
            txtSoHang.Text = gvPhongChieu.CurrentRow.Cells(3).Value.ToString()
            txtMoTa.Text = gvPhongChieu.CurrentRow.Cells(4).Value.ToString()
            cmbDKKT.Text = gvPhongChieu.CurrentRow.Cells(5).Value.ToString() 'bus.GetValue("select DKKT from PhongChieu where DKKT=" + gvPhongChieu.CurrentRow.Cells(5).Value.ToString())
            cmbTinhTrang.Text = gvPhongChieu.CurrentRow.Cells(6).Value.ToString() ' bus.GetValue("select TinhTrang from PhongChieu where TinhTrang=" + gvPhongChieu.CurrentRow.Cells(6).Value.ToString())
        Catch
        End Try
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim bus As PhongChieuBUS = New PhongChieuBUS()
        Dim tmp As PhongChieuDTO = New PhongChieuDTO()
        tmp.MaPhongChieu = Convert.ToInt32(lbMaPC.Text)
        bus.Delete(tmp)
        gvPhongChieu_Load()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If (txtMoTa.Text = "" Or txtSoDay.Text = "" Or txtSoHang.Text = "" Or cmbDKKT.Text = "" Or cmbMaRap.SelectedValue.ToString() = "" Or cmbTinhTrang.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim bus As PhongChieuBUS = New PhongChieuBUS()
            Dim pc As PhongChieuDTO = New PhongChieuDTO()
            pc.MaPhongChieu = lbMaPC.Text
            pc.SoDayGhe = Convert.ToInt32(txtSoDay.Text)
            pc.SoHangGhe = Convert.ToInt32(txtSoHang.Text)
            pc.MaRap = Convert.ToInt32(cmbMaRap.SelectedValue.ToString())
            pc.MoTa = txtMoTa.Text 'roi thu xem
            pc.DKKT = cmbDKKT.SelectedItem.ToString()
            pc.TinhTrang = cmbTinhTrang.SelectedItem.ToString()
            bus.Update(pc)
            gvPhongChieu_Load()
        End If
    End Sub




    'Quan ly phim

    Public Sub gvPhim_Load()
        Dim bus As PhimBUS = New PhimBUS()
        gvPhim.DataSource = bus.GetTable("select * from PHIM")
    End Sub

    Private Sub gvPhim_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvPhim.SelectionChanged
        Dim bus As PhimBUS = New PhimBUS()
        Try
            If gvPhim.SelectedRows.Count = 0 Then
                Return
            End If
            txtTenPhim.Text = gvPhim.CurrentRow.Cells(0).Value.ToString()
            txtGioiThieuPhim.Text = gvPhim.CurrentRow.Cells(1).Value.ToString()
            txtTrailerPhim.Text = gvPhim.CurrentRow.Cells(2).Value.ToString()
            txtPosterPhim.Text = gvPhim.CurrentRow.Cells(3).Value.ToString()
            txtThoiLuongPhim.Text = gvPhim.CurrentRow.Cells(4).Value.ToString()
            txtNamSXPhim.Text = gvPhim.CurrentRow.Cells(5).Value.ToString()
            txtNuocSXPhim.Text = gvPhim.CurrentRow.Cells(6).Value.ToString()
            txtHangPhim.Text = gvPhim.CurrentRow.Cells(7).Value.ToString()
        Catch
        End Try
    End Sub

    Private Sub btnThemPhim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemPhim.Click
        If (txtTenPhim.Text = "" Or txtGioiThieuPhim.Text = "" Or txtTrailerPhim.Text = "" Or txtPosterPhim.Text = "" Or txtThoiLuongPhim.Text = "" Or txtNamSXPhim.Text = "" Or txtNuocSXPhim.Text = "" Or txtHangPhim.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim p As PhimDTO = New PhimDTO()
            Dim bus As PhimBUS = New PhimBUS()
            Dim kt As String = "select * from PHIM where TenPhim='" + txtTenPhim.Text + "'"
            Dim dt = New DataTable
            dt = bus.GetTable(kt)
            If (dt.Rows.Count = 0) Then
                p.TenPhim = txtTenPhim.Text
                p.GioiThieu = txtGioiThieuPhim.Text
                p.Trailer = txtTrailerPhim.Text
                p.Poster = txtPosterPhim.Text
                p.ThoiLuong = txtThoiLuongPhim.Text
                p.NamSX = txtNamSXPhim.Text
                p.NuocSX = txtNuocSXPhim.Text
                p.HangPhim = txtHangPhim.Text
                bus.Insert(p)
                gvPhim_Load()
            Else
                MessageBox.Show("Ten phim da ton tai")
            End If
        End If
    End Sub

    Private Sub btnSuaPhim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaPhim.Click
        If (txtTenPhim.Text = "" Or txtGioiThieuPhim.Text = "" Or txtTrailerPhim.Text = "" Or txtPosterPhim.Text = "" Or txtThoiLuongPhim.Text = "" Or txtNamSXPhim.Text = "" Or txtNuocSXPhim.Text = "" Or txtHangPhim.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim bus As PhimBUS = New PhimBUS()
            Dim tmp As PhimDTO = New PhimDTO()
            tmp.GioiThieu = txtGioiThieuPhim.Text
            tmp.HangPhim = txtHangPhim.Text
            tmp.NamSX = txtNamSXPhim.Text
            tmp.NuocSX = txtNuocSXPhim.Text
            tmp.Poster = txtPosterPhim.Text
            tmp.TenPhim = txtTenPhim.Text
            tmp.ThoiLuong = txtThoiLuongPhim.Text
            tmp.Trailer = txtTrailerPhim.Text
            bus.Update(tmp)
            gvPhim_Load()
        End If
    End Sub

    Private Sub btnXoaPhim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaPhim.Click
        Dim bus As PhimBUS = New PhimBUS()
        Dim tmp As PhimDTO = New PhimDTO()
        tmp.TenPhim = txtTenPhim.Text
        bus.Delete(tmp)
        gvPhim_Load()
    End Sub

    Private Sub btnSetTheLoai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetTheLoai.Click
        Dim QT As frmTheLoaiPhim = New frmTheLoaiPhim()
        QT.ShowDialog()
    End Sub

    Private Sub cmbXemTheoPhim_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbXemTheoPhim.SelectedIndexChanged
        Dim bus As TheLoaiPhimBUS = New TheLoaiPhimBUS()
        Dim str As String = ""
        If cmbXemTheoPhim.Text = "Tất cả" Then
            str = "select  * from PHIM"
            gvPhim.DataSource = bus.GetTable(str)
        Else
            str = "select PHIM.TenPhim, GioiThieu, Trailer, Poster, ThoiLuong, NamSX, NuocSX, HangPhim from PHIM, THELOAIPHIM where TenTheLoai='" + cmbXemTheoPhim.Text + "' and PHIM.TenPhim = THELOAIPHIM.TenPhim"
            gvPhim.DataSource = bus.GetTable(str)
        End If
    End Sub

    Private Sub btnTimPhim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimPhim.Click
        If (rdTimTenPhim.Checked = True) Then
            Dim bus As PhimBUS = New PhimBUS()
            Dim str As String = "select * from PHIM where TenPhim like '%" + txtTimPhim.Text + "%'"
            gvPhim.DataSource = bus.GetTable(str)
        ElseIf (rdTimHangPhim.Checked = True) Then
            Dim bus As PhimBUS = New PhimBUS()
            Dim str As String = "select * from PHIM where HangPhim like '%" + txtTimPhim.Text + "%'"
            gvPhim.DataSource = bus.GetTable(str)
        ElseIf (rdTimNamSX.Checked = True) Then
            Dim bus As PhimBUS = New PhimBUS()
            Dim str As String = "select * from PHIM where NamSX like '%" + txtTimPhim.Text + "%'"
            gvPhim.DataSource = bus.GetTable(str)
        ElseIf (rdTimNuocSX.Checked = True) Then
            Dim bus As PhimBUS = New PhimBUS()
            Dim str As String = "select * from PHIM where NuocSX like '%" + txtTimPhim.Text + "%'"
            gvPhim.DataSource = bus.GetTable(str)
        End If
    End Sub


    Private Sub lbUserName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbUserName.Click

    End Sub
    Private Sub lbDangXuat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbDangXuat.Click

        Frm_Login.txtTenDN.Text = ""
        Frm_Login.txtMatKhau.Text = ""
        Frm_Login.txtTenDN.Select()
        Close()
    End Sub
End Class